// apply 以数组形式接收参数

function foo(x, y) {
  console.log(this.a, x, y);
}

const obj = {
  a: 1
}

foo.apply(obj, [2, 3])   // 1 2 3

Function.prototype.myApply = function (obj, args) {
  const context = obj
  context.fn = this
  const res = context.fn(...args)
  delete context.fn
  return res
}
foo.myApply(obj, [2, 3])   // 1 2 3